//
//  TemplateSingleContainer.swift
//  TemplateImageEditDemo
//
//  Created by liguandong on 2024/4/16.
//

import Foundation
import UIKit
// 点击增加图片和显示图片（不编辑）
class TemplateSingleContainer4 : UIView {
 
    lazy var addImageView: UIButton = {
        let button = UIButton()
        button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        button.setTitle("＋", for: .normal)
        button.setTitleColor(.black, for: .normal)
        button.layer.cornerRadius = 22
        button.layer.masksToBounds = true
        button.layer.borderColor = UIColor.black.cgColor
        button.layer.borderWidth = 1.0
        return button
    }()
    
    private(set) lazy var templateImageView : TemplateImageView4 = {
        let v = TemplateImageView4(frame: .zero)
        return v
    }()
    
    let index : Int
    private(set) var image : UIImage?
    init(_ index : Int){
        self.index = index
        super.init(frame: .zero)
        backgroundColor = .blue
        clipsToBounds = true
        addSubview(addImageView)
        addSubview(templateImageView)
        addImageView.snp.makeConstraints { make in
            make.width.height.equalTo(50)
            make.center.equalToSuperview()
        }
        templateImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    func setImage(_ image : UIImage){
        self.image = image
        templateImageView.image = image
        addImageView.isHidden = true
    }
    
    func resetStatus(){
        image = nil
        templateImageView.image = nil
        backgroundColor = .blue
        addImageView.isHidden = false
        templateImageView.transform = .identity

    }
   
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
